package xiaoka.ecarx.com.cn.youlong.player.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import xiaoka.ecarx.com.cn.youlong.player.ClientPlayerManager;
import xiaoka.ecarx.com.cn.youlong.upnp.MainActivity;

/**
 * Created by zhanghao on 2016/11/1.
 */

public class PlayerBroadcastReceiver extends BroadcastReceiver {

    private static final String TAG = PlayerBroadcastReceiver.class.getName();

    public static final String ACTION_DOWM = "cn.com.ecarx.xiaoka.action.MEDIA_BUTTON_DOWN";
    public static final String ACTION_UP = "cn.com.ecarx.xiaoka.action.MEDIA_BUTTON_UP";
    public static final String ACTION_DOUBLE_CLICK = "cn.com.ecarx.xiaoka.action.MEDIA_BUTTON_DOUBLE_CLICK";
    public static final String ACTION_ROTATE_RIGHT = "cn.com.ecarx.xiaoka.action.ROTATE_BUTTON_RIGHT";
    public static final String ACTION_ROTATE_LEFT = "cn.com.ecarx.xiaoka.action.ROTATE_BUTTON_LEFT";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d(TAG,"receive motion action = " + action);
        switch (action){
            case Intent.ACTION_BOOT_COMPLETED:
                context.startActivity(new Intent(context, MainActivity.class));
                break;
            case ACTION_DOWM:
                ClientPlayerManager.getInstance(context).play();
                break;
            case ACTION_UP:
                ClientPlayerManager.getInstance(context).pause();
                break;
            case ACTION_ROTATE_LEFT:
                ClientPlayerManager.getInstance(context).playPre();
                break;
            case ACTION_ROTATE_RIGHT:
                ClientPlayerManager.getInstance(context).playNext();
                break;
            case ACTION_DOUBLE_CLICK:
                ClientPlayerManager.getInstance(context).switchNextAlbum();
                break;
        }
    }

}
